﻿@namespace BootstrapBlazor.Components
@typeparam TValue
@inherits ValidateBase<TValue>

@if (IsShowLabel)
{
    <BootstrapLabel required="@Required" for="@Id" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
}
<div class="cascade menu">
    <div @attributes="AdditionalAttributes" id="@Id" data-bs-toggle="lgbSelect" class="@ClassName" tabindex="-1">
        <input type="text" id="@InputId" readonly disabled="@Disabled" class="@InputClassName" style="@BackgroundColor" data-bs-toggle="dropdown" placeholder="@PlaceHolder" value="@DisplayTextString" />
        <span class="@AppendClassName"><i class="fa fa-angle-up"></i></span>
        @if (!IsDisabled)
        {
            <div class="dropdown-menu shadow">
                <CascadingValue Value="SelectedItems">
                    @foreach (var item in Items)
                    {
                        if (item.HasChildren)
                        {
                            <div class="@ActiveItem("has-leaf dropdown-item", item)" data-val="@item.Value" @onclick="@(e => OnItemClick(item))">
                                <span>@item.Text</span>
                                <i class="fa fa-angle-down nav-link-right"></i>
                                <ul class="nav sub-menu" @onclick:stopPropagation>
                                    <SubCascader Items="@item.Items" OnClick="@OnItemClick" />
                                </ul>
                            </div>
                        }
                        else
                        {
                            <div class="@ActiveItem("dropdown-item", item)" data-val="@item.Value" @onclick="@(e => OnItemClick(item))">@item.Text</div>
                        }
                    }
                </CascadingValue>
            </div>
            <div class="dropdown-menu-arrow"></div>
        }
    </div>
</div>
<CascadingValue Value="this" IsFixed="true">
    @ChildContent
</CascadingValue>
